<?php
class EducationsController extends AppController {

	var $name = 'Educations';
	var $helpers = array('Html', 'Form');

	function index() 
    {
	    if($this->Session->read('User.type')=='jobseeker')
        {
            $this->set('choose1',32);
            $this->set('menu_resume',7);
            
            $this->Education->recursive=-1;
            if(!empty($this->data))
            {
                $this->Education->query("DELETE FROM `educations` WHERE `jobseeker_id`=".$this->Session->read('User.id'));
                $count = $this->data['counter'];
                for ($i=0;$i<$count;$i++)
                {
                    if($this->data[$i]['Education']['school']!="")
                    {
                        $this->data[$i]['Education']['jobseeker_id']=$this->Session->read('User.id');
                        $this->Education->create();
                        $this->Education->save($this->data[$i]);
                    }    
                }
                $this->Education->query("UPDATE `resumes` SET modified = '".date("Y-m-d")."' WHERE jobseeker_id=".$this->Session->read('User.id'));
                $this->redirect(array('controller'=>'works', 'action'=>'index'));
            }
            else
            {
                $educations = $this->Education->find("all",array('conditions'=>array('Education.jobseeker_id'=>$this->Session->read('User.id')), 'order'=>'Education.start_period'));
                $this->set('educations',$educations);
            }
        }
        else
        {
            $this->Session->setFlash(__('Please login first', true));
            $this->redirect(array('controller'=>'jobseekers', 'action'=>'login'),null, true);
        }
        
	}
}
?>